package cn.mrlong.cancelcircularprogressdialog;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import cn.mrlong.circularprogressdialog.CircularProgressDialog;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn = findViewById(R.id.btn);
        Button btn2 = findViewById(R.id.btn2);
        //设置一个取消按钮来取消
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new CircularProgressDialog(MainActivity.this, new CircularProgressDialog.CancelOnClickListener() {
                    @Override
                    public void cancel() {
                        Toast.makeText(MainActivity.this, "取消啦", Toast.LENGTH_SHORT).show();
                    }
                })
                        .setHintText("提示文字")
                        .setBackBtnCancelable(false).setOnTouchOutsideCancelable(false)
                        .show();
            }
        });
        //通过原有的方式可以取消：比如 返回按钮 触摸外部区域
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new CircularProgressDialog(MainActivity.this)
                        .setHintText("loading...")
                        .setBackBtnCancelable(true)
                        .setOnTouchOutsideCancelable(true)
                        .show();
            }
        });
    }
}
